home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / hardware / mccontrol / modules / ramcard_mcm.asm < prev    next >
Assembly Source File  |  1999-11-29  |  7KB  |  205 lines

  1. ;----------------------------------------------------------------------------
  2. ;    RamCard.mcm by Guido Mersmann
  3. ;----------------------------------------------------------------------------
  4.     include "Include.i"
  5.     ;include "SRC.MC_ModuleInclude"
  6.     output Sourcecodes:MCControl/Modules/RamCard.mcm
  7.     opt o+,w-
  8. ;----------------------------------------------------------------------------
  9. Version = 1
  10. Revision = 2
  11. Day = 19
  12. Month = 10
  13. Year = 99
  14. ;----------------------------------------------------------------------------
  15. ;--- Macros
  16. Version_String    MACRO
  17.     dc.b "$VER: ",\1,' \<Version>.\<Revision>'," (\<Day>.\<Month>.\<Year>) ",'\2',0
  18.     ENDM
  19. ;----------------------------------------------------------------------------
  20. ;--- Your defines
  21.  
  22. Card_Frame_SIZEOF    = 128
  23. Card_Checksumm_SIZEOF    = 1
  24. Card_Terminator_SIZEOF    = 1
  25.  
  26. Card_SuccessCode    = $47
  27. Card_ReadMode    = $52
  28. Card_WriteMode    = $57
  29.  
  30.     RSRESET
  31. FrameHeader_Device    rs.b 1 ;$81 Card!
  32. FrameHeader_Mode    rs.b 1 ;$52 = read, $57 = write)
  33. FrameHeader_Dummy1    rs.b 2
  34. FrameHeader_FrameHigh    rs.b 1
  35. FrameHeader_FrameLow    rs.b 1
  36. FrameHeader_WriteSizeOf    rs.b 0
  37. FrameHeader_Dummy2    rs.b 2
  38. FrameHeader_Dummy3    rs.b 2
  39. FrameHeader_ReadSizeOf    rs.b 0
  40. ;----------------------------------------------------------------------------
  41. ;----------------------------------------------------------------------------
  42.     RSSET Module_SIZEOF
  43. ;--- User Data
  44. Module_UserData    rs.b 0
  45. Module_Offset    rs.w 1
  46. Module_Buffer    rs.b Card_Frame_SIZEOF+FrameHeader_ReadSizeOf+Card_Checksumm_SIZEOF+Card_Terminator_SIZEOF
  47. ;--- Insert Userdata here!
  48. Module_UserData_End    rs.b 0
  49. ;----------------------------------------------------------------------------
  50. ;----------------------------------------------------------------------------
  51. DModule_Code    rts
  52. DModule_Version    dc.w 1
  53. DModule_ID    dc.l Module_Identifier
  54. DModule_Flags    dc.l 0 ;ModuleF_Delay ;ModuleF_MultiPage
  55. DModule_Exec_Base    dc.l 0 ;Filled by MCControl
  56. DModule_Dos_Base    dc.l 0 ;Filled by MCControl
  57. DModule_Intuition_Base    dc.l 0 ;Filled by MCControl
  58. ;--- Card Data
  59. DModule_DelayReadByte    dc.l 0 ;Filled by MCControl
  60. DModule_DelayReadBit    dc.l 0 ;Filled by MCControl
  61. DModule_DelayWriteByte    dc.l 0 ;Filled by MCControl
  62. DModule_DelayWriteBit    dc.l 0 ;Filled by MCControl
  63.     ds.l 10 ;reserved
  64. ;--- Jump Table
  65. DModule_Delay    ds.w 3 ;Delay
  66.     bra DModule_Open
  67.     nop
  68.     bra DModule_Close
  69.     nop
  70.     bra DModule_FrameOpen
  71.     nop
  72.     bra DModule_FrameClose
  73.     nop
  74.     bra DModule_ReadCommand
  75.     nop
  76.     bra DModule_WriteCommand
  77.     nop
  78.     bra DModule_PADOpen
  79.     nop
  80.     bra DModule_PADClose
  81.     nop
  82.     bra DModule_PADCommand
  83.     nop
  84.     ds.w 3*10 ;reserved
  85.     ds.b Module_UserData_End-Module_UserData
  86. ;----------------------------------------------------------------------------
  87.     Version_String "RamCard.mcm",<by Guido Mersmann>
  88.     even
  89. ;----------------------------------------------------------------------------
  90. ;--- Reset Offset!
  91. DModule_FrameOpen    lea    Module_Offset+DModule_Code(pc),a0
  92.     clr.w    (a0)+
  93.     move.l    #$ffff5a5d,(a0)+
  94.     move.l    #$ffff5c5d,(a0)+
  95. ;--- Cosmetic only! Fill Output Bytes with $ff
  96.     moveq    #((Card_Frame_SIZEOF/4)+1)-1,d0
  97.     moveq    #-1,d1
  98. .ClearBuffer_Loop    move.l    d1,(a0)+
  99.     dbra    d0,.ClearBuffer_Loop
  100. DModule_FrameClose
  101. DModule_PADOpen
  102. DModule_PADClose
  103. DModule_PADCommand
  104. DModule_Open
  105. DModule_Close    moveq    #Module_Error_NoError,d0
  106.     rts
  107. ;----------------------------------------------------------------------------
  108. DModule_ReadCommand
  109. DModule_WriteCommand    movem.l    d2-d4/a4,-(a7)
  110.     lea    Module_Offset+DModule_Code(pc),a4
  111.     move.w    (a4),d4
  112.     addq.w    #1,(a4)+
  113. ;--- Read Output and store Input Byte
  114.     move.b    (a4,d4.w),d1
  115.     move.b    d0,(a4,d4.w)
  116.     move.b    d1,d0
  117. ;--- Read Header or Write Header??
  118. ;--- This is very tricky, because the FrameHeader_Mode(a4) isn´t valid when
  119. ;--- reading the first byte. The handling of the first 6 Bytes is the 
  120. ;--- same for reading and and writing, so we can ignore this problem!
  121.     cmp.b    #Card_WriteMode,FrameHeader_Mode(a4)
  122.     beq    .WriteMode
  123. ;--- Make input frame number ready for output! This is tricky again! 
  124. ;--- Its not required to check frame bytes (low/high), because the 
  125. ;--- output frame won´t be used before the input gets valid.
  126.     move.b    FrameHeader_FrameHigh(a4),FrameHeader_Dummy3(a4)
  127.     move.b    FrameHeader_FrameLow(a4),FrameHeader_Dummy3+1(a4)
  128.     cmp.w    #FrameHeader_ReadSizeOf,d4
  129.     bne    .ReadWrite_Done
  130. ;--- Now we are calling the real hardware, to get 128 frame bytes!
  131. ;--- In addition to that, we code the checksumm and store the result!
  132.     moveq    #0,d0
  133.     move.b    FrameHeader_FrameHigh(a4),d0
  134.     move.b    d0,d2 ;Checksumm (XOR)
  135.     lsl.w    #8,d0
  136.     move.b    FrameHeader_FrameLow(a4),d0
  137.     eor.b    d0,d2 ;Checksumm (XOR)
  138.     lea    (a4,d4.w),a0
  139.     bsr    Card_ReadFrame
  140.     moveq    #Card_Frame_SIZEOF-1,d3
  141.     lea    (a4,d4.w),a0
  142. .Xor_Loop    move.b    (a0)+,d1
  143.     eor.b    d1,d2
  144.     dbra    d3,.Xor_Loop
  145.     move.b    d2,(a0)+
  146.     move.b    d0,(a0)
  147.     move.b    (a4,d4.w),d0
  148. .ReadWrite_Done    movem.l    (a7)+,d2-d4/a4
  149.     rts
  150. ;--- MCControl send Checksumm? Yes, then the frame is ready for transfer.
  151. .WriteMode    cmp.w    #FrameHeader_WriteSizeOf+Card_Frame_SIZEOF,d4
  152.     bne    .ReadWrite_Done
  153. ;--- Very easy! Just accessing the hardware and write 128 frame bytes.
  154.     moveq    #0,d0
  155.     move.b    FrameHeader_FrameHigh(a4),d0
  156.     lsl.w    #8,d0
  157.     move.b    FrameHeader_FrameLow(a4),d0
  158.     lea    FrameHeader_WriteSizeOf(a4),a0
  159.     bsr    Card_WriteFrame
  160.     lea    FrameHeader_WriteSizeOf+Card_Frame_SIZEOF+Card_Checksumm_SIZEOF(a4),a0
  161.     move.b    #$5c,(a0)+
  162.     move.b    #$5d,(a0)+
  163.     move.b    d0,(a0)
  164.     bra    .ReadWrite_Done
  165. ;----------------------------------------------------------------------------
  166. ;----------------------------------------------------------------------------
  167. ; Insert Hardware read/write code below! (> = Input, < = Output)
  168. ;----------------------------------------------------------------------------
  169. ;----------------------------------------------------------------------------
  170. ;    Card_ReadFrame
  171. ;    >a0.l Pointer on Destination
  172. ;    >d0.l Number of Frame
  173. ;    <d0.b Card_SuccessCode = Ok, NULL = Error
  174. ; Just like AmigaOS!! Only change a0,a1,d0,d1!!!
  175. ;----------------------------------------------------------------------------
  176. ;----------------------------------------------------------------------------
  177. Card_ReadFrame    lea    RAMCARD,a1
  178.     mulu    #Card_Frame_SIZEOF,d0
  179.     add.l    d0,a1
  180.     moveq    #Card_Frame_SIZEOF-1,d0
  181. .Loop    move.b    (a1)+,(a0)+
  182.     dbra    d0,.Loop
  183.     moveq    #Card_SuccessCode,d0 ;NoError
  184.     rts
  185. ;----------------------------------------------------------------------------
  186. ;----------------------------------------------------------------------------
  187. ;    Card_WriteFrame
  188. ;    >a0.l Pointer on Source
  189. ;    >d0.l Number of Frame
  190. ;    <d0.b Card_SuccessCode = Ok, NULL = Error
  191. ; Just like AmigaOS!! Only change a0,a1,d0,d1!!!
  192. ;----------------------------------------------------------------------------
  193. ;----------------------------------------------------------------------------
  194. Card_WriteFrame    lea    RAMCARD,a1
  195.     mulu    #Card_Frame_SIZEOF,d0
  196.     add.l    d0,a1
  197.     moveq    #Card_Frame_SIZEOF-1,d0
  198. .Loop    move.b    (a0)+,(a1)+
  199.     dbra    d0,.Loop
  200.     moveq    #Card_SuccessCode,d0 ;NoError
  201.     rts
  202. ;----------------------------------------------------------------------------
  203.     Section "RamCard",BSS
  204. RAMCARD    ds.b 2*65536
  205.